package com.bjpowernode.aspect.exercise;

import com.bjpowernode.aspect.exercise.beans.*;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyApp2 {
    public static void main(String[] args) throws Throwable {
        Stu stu = new Stu();
        Teacher teacher = new Teacher();
        Worker worker = new Worker();
        Bus bus = new Bus();


        //JDK代理框架
        JDKProxy proxy=new JDKProxy();
        proxy.setTarget(stu);
        //接口方法
        //Method doing = IA.class.getMethod("doing");
        //代理类对象【JDK提供一个Proxy类的静态方法newProxyInstance来获取代理类实例】
        //该代理类，可以直接转换成IA接口
        IA proxyInstance =(IA) Proxy.newProxyInstance(MyApp2.class.getClassLoader(),new Class[]{IA.class},proxy);
        //使用JDK代理框架对象完成代理方法
        //proxy.invoke(proxyInstance,doing,null);
        //使用代理对象完成代理方法
        proxyInstance.doing();
        
    }
}
